package com.my.admin.web;

import java.util.List;

import com.my.admin.domain.Admin;
import com.my.admin.service.AdminService;
import com.opensymphony.xwork2.ActionSupport;

public class AdminAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = -3907109854233033691L;
	private Admin admin;
	private AdminService adminService;

	/**
	 * @return the admin
	 */
	public Admin getAdmin() {
		return admin;
	}

	/**
	 * @param admin
	 *            the admin to set
	 */
	public void setAdmin(Admin admin) {
		this.admin = admin;
	}

	@Override
	public String execute() {
		return this.SUCCESS;
	}

	public String login() {
		List<Admin> adminList = this.adminService.getAdminByParam(this.admin);
		if (!adminList.isEmpty()) {
			admin = null;
			addActionMessage("Login Successful!");
			return this.SUCCESS;
		} else {
			addActionError("User name or Password Error!");
			return this.INPUT;
		}
	}

	/**
	 * @return the adminService
	 */
	public AdminService getAdminService() {
		return adminService;
	}

	/**
	 * @param adminService
	 *            the adminService to set
	 */
	public void setAdminService(AdminService adminService) {
		this.adminService = adminService;
	}
}
